
import * as nodePath from "path";
import * as nodeFileSys from "fs";
import { TokenInfo } from "./TokenInfo";

export function getCodeCallbackUrl(): string {
  return "http://127.0.0.1:9100/net_disk/save-code";
}

export function getAuthorizationCodeUrl(): string {
  return "http://127.0.0.1:9100/net-disk/baidu/authorization/authorization-code";
}

export const tokenFilePath = nodePath.join(process.cwd(), "static/net-disk/baidu-token.git-ignore.json");

export async function getTokenInfo(): Promise<TokenInfo | null> {
  if (nodeFileSys.existsSync(tokenFilePath)) {
    const content = await nodeFileSys.promises.readFile(tokenFilePath, "utf-8");
    try {
      return JSON.parse(content);
    } catch(err) {
      console.error(err);
      return null;
    }
  }
  return null;
} 